home *** CD-ROM | disk | FTP | other *** search
/ Interactive Web Graphics with Shout 3D / Interactive Web Graphics With Shout 3D.iso / mac / Code / Chapter09 / SwingPanel.java < prev    next >
Text File  |  2000-07-06  |  1KB  |  58 lines

  1.  
  2.  
  3.  
  4. package applets;
  5.  
  6. import shout3d.*;
  7. import shout3d.core.*;
  8. import shout3d.math.*;
  9.  
  10.  
  11. public class SwingPanel extends Shout3DPanel implements RenderObserver{
  12.     
  13.     
  14.     Transform t;
  15.     float cycleAngle = 0;
  16.     float limit = 3.0f;
  17.     float cycleTime = 4.0f; //seconds per cycle
  18.  
  19.     public SwingPanel (Shout3DApplet applet){
  20.         super(applet);
  21.     }
  22.     
  23.     
  24.         public void customInitialize() {
  25.  
  26.         getRenderer().addRenderObserver(this, null);
  27.         t = (Transform) getNodeByName("trans");
  28.     
  29.     }
  30.  
  31.  
  32.     protected void finalize()  { 
  33.         getRenderer().removeRenderObserver(this);
  34.     }
  35.  
  36.  
  37.     public void onPreRender (Renderer r, Object o) {
  38.         
  39.         //change in angle around cycle
  40.         float deltaAngle = (6.28f/cycleTime)/getFramesPerSecond();
  41.  
  42.         //update angle
  43.         cycleAngle = cycleAngle + deltaAngle;
  44.  
  45.         //convert angle to x position
  46.         float xPos    = (float) (Math.cos(cycleAngle) * limit);
  47.  
  48.         //update Transform
  49.         t.translation.set1Value(0, xPos);
  50.     }
  51.     
  52.  
  53.     public void onPostRender (Renderer r, Object o) {
  54.     
  55.     
  56.     }
  57.  
  58. } //end of class